package sangpil.motionGuide.viewer
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import sangpil.motionGuide.viewer.event.ViewerEvent;
	[Event( name="sendObject", type="sangpil.motionGuide.viewer.event.ViewerEvent")]
	public class SetTest extends Sprite
	{
		private var clip:basesetClip
		private var imgSet:Sprite;
		private var imgArr:Array = [];
		private var baseArr:Array = [];
		public var totalArr:Array = [];
		private var space:Number = 3;
		private var leftIn:Number = 85;
		private var topIn:Number = 245.0;
		public function SetTest()
		{
			super();
			this.setLayout();
			this.setDefault();
		}
		
		private function setLayout():void
		{
			this.clip = new basesetClip();
			this.clip.name = 'basic set';
			this.addChild(this.clip);
			
			var count:uint = 0;
			
			this.imgSet = new Sprite();
			for(var i:uint = 0; i < 5; i++)
			{
				for(var j:uint = 0; j < 3; j++)
				{
					this.imgArr[count] = new imageBox();
					this.imgArr[count].name = 'imageIcon'+count;
					this.imgSet.addChild(this.imgArr[count]);
					this.imgArr[count].x = (imgArr[count].width+space) * j + leftIn;
					this.imgArr[count].y = (imgArr[count].height+space) * i + topIn;
					count++;
				}
			}
			this.addChild(this.imgSet);
		}
		
		private var infoArr:Array = new Array(
		
		{duration:1, delay:0 , eX:-390, eY:36, escale:1, erotation:1, ealpha:1  },
		{duration:1, delay:0 , eX:-322, eY:453, escale:1, erotation:-3, ealpha:1  },//bg
		{duration:1, delay: 0, eX:-361, eY:95, escale:1, erotation:-18, ealpha:1  },
		{duration:1, delay:0 , eX:-365, eY:78, escale:1, erotation:21, ealpha:1  },
		{duration:1, delay:0 , eX:-292, eY:77, escale:1, erotation:1, ealpha:1  },
		{duration:1, delay:0 , eX:-529, eY:157, escale:1, erotation:-6, ealpha:1  },//list
		{duration:1, delay:0 , eX:-168, eY:0, escale:1, erotation:-5, ealpha:1  },//num
		{duration:1, delay:0 , eX:240, eY:70, escale:1, erotation:1, ealpha:1  },
		
		{duration:1, delay:0.1 , eX:-351, eY:228, escale:1, erotation:30, ealpha:1  },//0
		{duration:0.7, delay:0.3 , eX:-300, eY:177, escale:1, erotation:-14, ealpha:1  },
		{duration:0.8, delay:0.2 , eX:-202, eY:241, escale:1, erotation:10, ealpha:1  },
		{duration:1, delay:0 , eX:-388, eY:411, escale:1, erotation:-6, ealpha:1  },
		{duration:1, delay:0 , eX:-278, eY:454, escale:1, erotation:0, ealpha:1  },//4
		{duration:0.6, delay:0.1 , eX:-120, eY:412, escale:1, erotation:14, ealpha:1  },//5
		{duration:1, delay:0 , eX:-402, eY:577, escale:1, erotation:8, ealpha:1  },//6
		{duration:0.6, delay:0.2 , eX:-251, eY:507, escale:1, erotation:9, ealpha:1  },//7
		{duration:0.7, delay:0.1 , eX:-226, eY:497, escale:1, erotation:-18, ealpha:1  },//8
		{duration:1, delay:0 , eX:-318, eY:698, escale:1, erotation:32, ealpha:1  },//9
		{duration:1, delay:0 , eX:-257, eY:644, escale:1, erotation:-17, ealpha:1  },//10
		{duration:1, delay:0 , eX:-166, eY:662, escale:1, erotation:10, ealpha:1  },//11
		{duration:1, delay:0 , eX:-374, eY:800, escale:1, erotation:21, ealpha:1  },//12
		{duration:1, delay:0 , eX:-291, eY:800, escale:1, erotation:0, ealpha:1  },//13
		{duration:1, delay:0 , eX:-89, eY:800, escale:1, erotation:-9, ealpha:1  }//14
		)
		
												
					
		private function setDefault():void
		{
			this.baseArr.push(this.clip.att, this.clip.background, this.clip.centerText, 
								this.clip.iconLeft, this.clip.iconRight, this.clip.listOne,
								this.clip.num, this.clip.upBg);
								
			this.totalArr = this.baseArr.concat(this.imgArr);
			
			for(var i:uint = 0; i < this.totalArr.length; i++)
			{
				this.totalArr[i].buttonMode = true;
				
				var dO:Object = new Object();
				dO.id = i;
				dO.name = this.totalArr[i].name;
				dO.saved = false;
				dO.activate = false;
				dO.delay = infoArr[i].delay;
				dO.duration = infoArr[i].duration;
				dO.ease = '';
				dO.easeData = null;
				this.totalArr[i].defaultInfo = dO;
				
				var sO:Object = new Object();
				sO.x = this.totalArr[i].x;
				sO.y = this.totalArr[i].y;
				sO.scale = 1;
				sO.rotation = 0;
				sO.alpha = 1;
				this.totalArr[i].startInfo = sO;
				
				var eO:Object = new Object();
				eO.x = infoArr[i].eX;
				eO.y = infoArr[i].eY;
				eO.scale = infoArr[i].escale;
				eO.rotation = infoArr[i].erotation;
				eO.alpha = infoArr[i].ealpha;
				this.totalArr[i].endInfo = eO;
				
				
				this.totalArr[i].addEventListener(MouseEvent.MOUSE_DOWN, selectOne);
				this.totalArr[i].addEventListener(MouseEvent.MOUSE_UP, selectUp);
			}
			
		}
		
		
		private function selectOne(e:MouseEvent):void
		{
			//trace('this is = ' + e.currentTarget);
			this.dispatchEvent(new ViewerEvent(e.currentTarget.defaultInfo, e.currentTarget.startInfo, e.currentTarget.endInfo, ViewerEvent.SEND_OBJECT));
			e.currentTarget.alpha = 0.5;
		}
		
		private function selectUp(e:MouseEvent):void
		{
			e.currentTarget.alpha = 1;
		}
		
	}
}